//订单查询
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            storeOrderCartManageInfo: {
                orderCarts: [],
                total: 0,
                records: 1,
                orderDetail: false,
                shops: [],
                conditions: {
                    cartId: '',
                    state: '',
                    shopId: '',
                    prodName: '',
                    mallApiCode:'queryAdminStoreOrderCartBmoImpl'
                },
                address: {
                    username: '',
                    tel: '',
                    address: ''
                },
                curOrderCart: {}
            }
        },
        _initMethod: function() {
            $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._listOrderShops(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function() {
            vc.on('storeOrderCartManage', 'goBack', function(_param) {
                $that.storeOrderCartManageInfo.orderDetail = false;
            });
            vc.on('storeOrderCartManage', 'list', function() {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function(_currentPage) {
                $that._listOrders(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listOrders: function(_page, _rows) {
                $that.storeOrderCartManageInfo.conditions.page = _page;
                $that.storeOrderCartManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.storeOrderCartManageInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/mall.getAdminMallOpenApi',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartManageInfo.total = _json.total;
                        $that.storeOrderCartManageInfo.records = _json.records;
                        $that.storeOrderCartManageInfo.orderCarts = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.storeOrderCartManageInfo.records,
                            dataCount: $that.storeOrderCartManageInfo.total,
                            currentPage: _page
                        });
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _listOrderShops: function(_page, _rows) {
                var param = {
                    params: {
                        page: _page,
                        row: _rows,
                        mallApiCode:'queryShopsByAdminBmoImpl'
                    }
                };

                //发送get请求
                vc.http.apiGet('/mall.getAdminMallOpenApi',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartManageInfo.total = _json.total;
                        $that.storeOrderCartManageInfo.records = _json.records;
                        $that.storeOrderCartManageInfo.shops = _json.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _queryOrdersMethod: function() {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openOrderDetailModel: function(_order) {
                vc.jumpToPage('/#/pages/goods/storeOrderCartDetail?orderId=' + _order.orderId + '&cartId=' + _order.cartId);
            },
            
            clearAddress: function() {
                $that.storeOrderCartManageInfo.address = {
                    username: '',
                    tel: '',
                    address: ''
                }
            },
            _closeStoreOrderCartModal: function() {
                $("#storeOrderCartModal").modal('hide');
            },
            
        }
    });
})(window.vc);